enableremote: Disallow using type= to attempt to change the type of an existing remote
authorJoey Hess <joeyh@joeyh.name>
Mon, 22 Sep 2025 14:54:16 +0000 (10:54 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 22 Sep 2025 14:54:16 +0000 (10:54 -0400)
Changing the type out from under an existing special remote exposes the
existing config to something that may interpret it wildly differently. As
seen in the bug report, this can even result in behavior that makes
git-annex say it's buggy. So prevent the user from doing this. --sameas is
the better way.

Sponsored-by: Kevin Mueller
CHANGELOG
Command/EnableRemote.hs
doc/bugs/enableremote_type__61__rclone_on_existing_remote_crash.mdwn

index acb06c4485b87b81d0d6298ac1154e5c5fd01080..530a560e34660a4306102750b8fa8f103887b55a 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -19,6 +19,8 @@ git-annex (10.20250829) UNRELEASED; urgency=medium
     and a repository in the directory got removed.
   * Added annex.assistant.allowunlocked config.
   * Add git-remote-p2p-annex and git-remote-tor-annex to standalone builds.
+  * enableremote: Disallow using type= to attempt to change the type of an
+    existing remote.
 
  -- Joey Hess <id@joeyh.name>  Fri, 29 Aug 2025 12:34:06 -0400
 
index 3aeae7147efdf16008ef8079ad9f354ea01dcdc0..875231d45893026ade98e17c52759281487969f6 100644 (file)
@@ -59,8 +59,11 @@ start _ [] = unknownNameError "Specify the remote to enable."
 start o (name:rest) = go =<< filter matchingname <$> Annex.getGitRemotes
   where
        matchingname r = Git.remoteName r == Just name
-       go [] = deadLast name $ 
-               startSpecialRemote o name (Logs.Remote.keyValToConfig Proposed rest)
+       go [] = deadLast name $
+               let config = Logs.Remote.keyValToConfig Proposed rest
+               in case M.lookup SpecialRemote.typeField config of
+                       Nothing -> startSpecialRemote o name config
+                       Just _ -> giveup "Cannot change type= of existing special remote. Instead, use: git-annex initremote --sameas"
        go (r:_)
                | not (null rest) = go []
                | otherwise = do
index 21a7c72cb616c89331de34cfae47622a931262d0..0fd5af8a1fc9890541d080b336d4f4682f1297ef 100644 (file)
@@ -40,3 +40,6 @@ Using the standalone amd64 build on Debian 12.
 ### Have you had any luck using git-annex before? (Sometimes we get tired of reading bug reports all day and a lil' positive end note does wonders)
 
 I use git-annex for "everything". I have somewhere along the lines of 14TiB stored in various git-annex repositories, synced in various degrees to anywhere between 3 and 10 hosts, with repos dating back to 2012. It's awesome.
+
+> [[fixed|done]] the git-annex bug by providing a better error message when
+> this is attempted. --[[Joey]]